/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package biblio.bl;

import biblio.modelo.Autor;
import biblio.dao.AutorDaoLocal;
import biblio.enumeracion.EstadoTransaccion;
import java.util.List;
import javax.ejb.EJB;
import javax.ejb.Stateless;

/**
 *
 * @author chava
 */
@Stateless
public class AutorBl implements AutorBlLocal {

    @EJB
    private AutorDaoLocal autorDao;

    /**
     *
     * @param author
     */
    @Override
    public EstadoTransaccion register(Autor author) {
        if (autorDao.FindDuplicity(author)) {
            return EstadoTransaccion.INCOMPLETO;
        } else {
            autorDao.create(author);
            return EstadoTransaccion.COMPLETO;
        }

    }

    @Override
    public EstadoTransaccion modify(Autor author) {
        if (author.getId() == null || autorDao.find(author.getId()) == null) {
            return EstadoTransaccion.INCOMPLETO;
        } else {
            autorDao.edit(author);
            return EstadoTransaccion.COMPLETO;
        }
    }

    @Override
    public EstadoTransaccion delete(Autor author) {
        if (author.getId() == null || autorDao.find(author.getId()) == null) {
            return EstadoTransaccion.INCOMPLETO;
        } else {
            autorDao.remove(author);
            return EstadoTransaccion.COMPLETO;
        }
    }
    
    
    // Add business logic below. (Right-click in editor and choose
    // "Insert Code > Add Business Method")

    @Override
    public List<Autor> getListAll() {
        return autorDao.findAll();
    }
}
